package front

import (
	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
)

type IndexController struct{}

func (con IndexController) Index(c *gin.Context) {

	session := sessions.Default(c)
	session.Set("username", "张三")
	session.Save()
	c.String(200, "前台首页")
}

func (con IndexController) News(c *gin.Context) {

	session := sessions.Default(c)
	username := session.Get("username")
	c.String(200, "username is %v", username)
}

// 删除cookie，只需要把存活时间设置成负数
func (con IndexController) DeleteCookie(c *gin.Context) {
	c.SetCookie("username", "张三", -1, "/", "localhost", false, false)
	c.String(200, "删除成功")
}
